package com.onlinelearn.courseservice.controller;

import com.onlinelearn.courseservice.dto.CourseDTO;
import com.onlinelearn.courseservice.model.CourseCategory;
import com.onlinelearn.courseservice.model.CourseStatus;
import com.onlinelearn.courseservice.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/courses")
public class CourseController {
    @Autowired
    private CourseService courseService;

    @PostMapping
    public ResponseEntity<CourseDTO> createCourse(@RequestBody CourseDTO courseDTO) {
        CourseDTO createdCourse = courseService.createCourse(courseDTO);
        return ResponseEntity.ok(createdCourse);
    }

    @GetMapping
    public ResponseEntity<List<CourseDTO>> getCourses(
            @RequestParam CourseCategory category,
            @RequestParam CourseStatus status
    ) {
        List<CourseDTO> courses = courseService.getCoursesByCategory(category, status);
        return ResponseEntity.ok(courses);
    }
} 